/*
 * @Description: 扣款顺序页面的api协议解析
 * @Author: tao.xie
 * @Date: 2019-03-26 14:06:01
 * @Last Modified by: tao.xie
 * @Last Modified time: 2019-04-02 17:07:28
 */
// import ajaxAsync from 'vue-xiaobu-utils'
import PaymentInfo from '../model/PaymentInfo'
import ajaxAsync from 'vue-xiaobu-utils'

/**
 *获取扣款顺序列表
 *
 * @returns
 */
async function getPaymentOrderList() {
  let rs = await ajaxAsync('/payment/order', {})
  let bankOrderList = []
  if (rs.LIST) {
    rs.LIST.map(item => {
      bankOrderList.push(
        new PaymentInfo(
          item.PAYMENT_ORDER_ID,
          item.PAYMENT_NAME,
          item.BANK_CARD_SHORT_NO,
          item.PAYMENT,
          item.PAY_ACCOUNT
        )
      )
    })
  }
  return bankOrderList
}

/**
 *获取卡类型相关的扣款顺序
 *
 * @param {String} cardInstanceId 卡实例编号
 * @param {Integer} cardType 卡类型
 * @returns
 */
async function getPaymentOrderListByCard(cardInstanceId, cardType) {
  let rs = await ajaxAsync('/vcard/payment/order', {
    CARD_INSTANCE_ID: cardInstanceId,
    CARD_TYPE: cardType
  })
  let bankOrderList = []
  if (rs.LIST) {
    rs.LIST.map(item => {
      bankOrderList.push(
        new PaymentInfo(
          item.PAYMENT_ORDER_ID,
          item.PAYMENT_NAME,
          item.BANK_CARD_SHORT_NO,
          item.PAYMENT,
          item.PAY_ACCOUNT,
          item.IS_SUPPORT
        )
      )
    })
  }
  return bankOrderList
}

/**
 *修改扣款顺序
 *
 * @param {Object} orderlist 扣款信息数组
 * @returns
 */
async function updatePaymentOrderList(orderlist) {
  let orderIdList = []
  orderlist.map(item => {
    orderIdList.push(item.paymentOrderId)
  })
  let rs = await ajaxAsync('/payment/order/update', { LIST: orderIdList })
  return rs
}

/**
 *获取钱包余额
 *
 * @returns
 */
async function getWalletBalance() {
  return ajaxAsync('/wallet/balance/get', {})
}

export {
  getPaymentOrderList,
  getPaymentOrderListByCard,
  updatePaymentOrderList,
  getWalletBalance
}
